<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MELANGE.
 *
 * PHP-MELANGE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MELANGE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MELANGE; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-melange
 * @subpackage  cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */
?>
<?=$this->header()?>


    <?=$this->menu("content")?>


    <h1><?=$this->message("label.header", _Content::BUNDLE)?></h1>


    <? /* Breadcrums route & content info display */ ?>
    <?=$this->route(
        array(
            array(
                "name"=>$this->message("label.category.header", _Content::BUNDLE),
                "href"=>"content/category/index"
            ),
            $this->category($this->contentListForm->getId())
        ), // Route display
        $this->contentListForm,                             // ListForm (for content info, see float right)
        $this->contents($this->contentListForm)->getRows())    // The total amount of contents
    ?>


    <? /* Show status messages */ ?>
    <?=$this->messages(_Core::BUNDLE)?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _Core::BUNDLE)?>


    <form id="<?=get_class($this->contentListForm)?>"
          method="post"
          action="content/index"
          onsubmit="return confirmDelete('<?=$this->message("message.confirm.delete", _Core::BUNDLE)?>', this)">


        <? /* Show the Search & Filter Panel */ ?>
        <?=$this->panel(
            "content/edit?contentI18n->content->categoryId=".$this->contentListForm->getId(), // Add New URL
            $this->contentListForm,       // ListForm
            array(                     // Filter fields
                ContentI18nPeer::NAME=>$this->message("prompt.name", _Content::BUNDLE),
                ContentI18nPeer::BODY=>$this->message("prompt.body", _Content::BUNDLE),
                ContentI18nPeer::INSERT_DATE=>$this->message("choose.created", _Core::BUNDLE),
                ContentI18nPeer::MODIFIED_DATE=>$this->message("choose.modified", _Core::BUNDLE),
                ContentI18nPeer::ACTIVE=>$this->message("choose.active", _Core::BUNDLE)
            )
        )?>


        <? /* Start output buffering in case there are no results */ ?>
        <?$this->start()?>


        <table class="list" cellspacing="0" cellpadding="0">
        <tr>
            <th class="checkbox"></th>
            <? /* <th class="narrow"></th> */ ?>

            <? /* Hide i18n if disabled */ ?>
            <? if($this->param(_Core::I18N)): ?>
                <th class="narrow" title="<?=$this->message("title.language", _Core::BUNDLE)?>">
                    <?=$this->message("label.language", _Core::BUNDLE)?>
                </th>
            <? endif; ?>

            <th>
                <?=$this->TH(
                    $this->contentListForm,                                 // ListForm
                    ContentI18nPeer::NAME,                               // Sort Field
                    $this->message("prompt.name", _Content::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->contentListForm,                         // ListForm
                    "linkCount",                                    // Sort Field
                    $this->message("label.links", _Content::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->contentListForm,                            // ListForm
                    ContentI18nPeer::MODIFIED_DATE,                 // Sort Field
                    $this->message("choose.modified", _Core::BUNDLE)  // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->contentListForm,                            // ListForm
                    ContentI18nPeer::INSERT_DATE,                   // Sort Field
                    $this->message("choose.created", _Core::BUNDLE)   // Header Name
                )?>
            </th>
            <? /*
            <th class="narrow" title="<?=$this->message("title.featured", _Core::BUNDLE)?>">
                <?=$this->TH(
                    $this->contentListForm,                         // ListForm
                    ContentI18nPeer::FEATURED,                      // Sort Field
                    $this->message("label.featured", _Core::BUNDLE) // Header Name
                )?>
            </th> */ ?>
            <th class="narrow" title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                <?=$this->TH(
                    $this->contentListForm,                            // ListForm
                    ContentI18nPeer::ACTIVE,                        // Sort Field
                    $this->message("label.active", _Core::BUNDLE)     // Header Name
                )?>
            </th>

            <? /* Only show available move arrows & available languages when language selectbox is on ALL */ ?>
            <? if(strlen($this->contentListForm->getLanguage()) == 0 &&
                    strlen($this->contentListForm->getQuery()) == 0): ?>

                <? /*
                <th class="narrow" title="<?=$this->message("title.order", _Core::BUNDLE)?>">
                    <?=$this->TH(
                        $this->contentListForm,                       // ListForm
                        ContentPeer::POSITION,                        // Sort Field
                        $this->message("label.order", _Core::BUNDLE), // Header Name
                        "ASC"
                    )?>
                </th> */ ?>

                <? /* Hide i18n if disabled */ ?>
                <? if($this->param(_Core::I18N)): ?>
                    <th class="narrow" title="<?=$this->message("title.language.available", _Core::BUNDLE)?>">
                        <?=$this->message("label.language.available", _Core::BUNDLE)?>
                    </th>
                <? endif; ?>

            <? endif; ?>

            <th class="buttons"></th>
        </tr>

        <? foreach($this->contents($this->contentListForm)->getItems() as $contentI18n) { ?>

            <? /* Display the default language content */ ?>
            <tr class="ctrl">
                <td class="checkbox">
                    <input type="checkbox"
                           name="items[]"
                           value="<?=$contentI18n->getContentI18nId()?>"
                           <?=in_array($contentI18n->getContentI18nId(), $this->contentListForm->getItems()) ? " checked=\"checked\"" : ""?> />

                </td>

                <? /*
                <td>
                    <? if($contentI18n->getContent()->getImageId() > 0): ?>
                    <a title="<?=$this->message("title.image", _Core::BUNDLE)?>" href="image?id=<?=$contentI18n->getContent()->getImageId()?>">
                        <?=$this->thumbnail($contentI18n->getContent()->getThumbnailId())?>
                    </a>
                    <? endif; ?>
                </td> */ ?>

                <? /* Hide i18n if disabled */ ?>
                <? if($this->param(_Core::I18N)): ?>
                    <td title="<?=$this->message("title.language", _Core::BUNDLE)?>">

                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($contentI18n->getLanguage()->getCode()).".png")?>"
                             width="16" height="11" alt="<?=$contentI18n->getLanguage()->getName()?>"
                             title="<?=$contentI18n->getLanguage()->getName()?>" class="flag" />

                    </td>
                <? endif; ?>

                <td title="<?=htmlentities($contentI18n->getName())?>"><?=$this->truncateNicely($contentI18n->getName(), 66, 70, "...")?></td>
                <td title="<?=$this->message("title.link.items", _Content::BUNDLE)?>">
                    <input type="button"
                           onclick="to('content/link/index?id=<?=$contentI18n->getContentId()?>')"
                           class="button"
                           value="<?=$contentI18n->getContent()->getLinkCount()?>" />
                    <?/* ?><a href="content/link/index?id=<?=$contentI18n->getContentId()?>">
                        <?=$contentI18n->getContent()->getLinkCount()?>
                    </a>*/?>
                </td>
                <td title="<?=$this->message("title.modified", _Core::BUNDLE)?> <?=$contentI18n->getModifiedDate(_Core::FORMAT_DATETIME)?>">
                    <?=$contentI18n->getModifiedDate(_Core::FORMAT_DATE)?>
                </td>
                <td title="<?=$this->message("title.created", _Core::BUNDLE)?> <?=$contentI18n->getInsertDate(_Core::FORMAT_DATETIME)?>">
                    <?=$contentI18n->getInsertDate(_Core::FORMAT_DATE)?>
                </td>
                <? /*
                <td title="<?=$this->message("title.featured", _Core::BUNDLE)?>">
                    <?=$this->message("label." . ($contentI18n->getFeatured() ? "yes" : "no"), _Core::BUNDLE)?>
                </td> */ ?>
                <td title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                    <?=$this->message("label." . ($contentI18n->getActive() ? "yes" : "no"), _Core::BUNDLE)?>
                </td>

                <? /* Only show available move arrows & available languages when language selectbox is on ALL */ ?>
                <? if(strlen($this->contentListForm->getLanguage()) == 0 &&
                      strlen($this->contentListForm->getQuery()) == 0): ?>

                    <? /*
                    <td title="<?=$this->message("title.move", _Core::BUNDLE)?>">

                        <? if($contentI18n->getContent()->getPosition() > 1): ?>
                            <input type="image" onclick="moveup(<?=$contentI18n->getContentId()?>, this.form)"
                                   src="static.php?file=<?=$this->image("cms/core/view/gfx/arrow_up.png")?>" alt=""
                                   alt="<?=$this->message("title.move.up", _Core::BUNDLE)?>"
                                   title="<?=$this->message("title.move.up", _Core::BUNDLE)?>. <?=$this->message("title.move", _Core::BUNDLE)?>" />
                        <? endif; ?>

                        <? if($contentI18n->getContent()->getPosition() < $contentI18n->getContent()->getMaxPosition()): ?>
                            <input type="image" onclick="movedown(<?=$contentI18n->getContentId()?>, this.form)"
                                   src="static.php?file=<?=$this->image("cms/core/view/gfx/arrow_down.png")?>"
                                   alt="<?=$this->message("title.move.down", _Core::BUNDLE)?>"
                                   title="<?=$this->message("title.move.down", _Core::BUNDLE)?>. <?=$this->message("title.move", _Core::BUNDLE)?>" />
                        <? endif; ?>

                    </td> */ ?>

                    <? /* Hide i18n if disabled */ ?>
                    <? if($this->param(_Core::I18N)): ?>
                        <td title="<?=$this->message("title.language.available", _Core::BUNDLE)?>">

                            <? /* Only show available languages when item language same as CMS default language) */ ?>
                            <? if($contentI18n->getLanguageCode() == $this->param(_Core::DEFAULT_LANGUAGE)) { ?>
                                <? foreach($contentI18n->getAvailableLanguages() as $language) { ?>
                                    <a href="content/edit?contentI18n->contentId=<?=$contentI18n->getContentId()?>&amp;contentI18n->languageCode=<?=$language->getCode()?>">
                                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($language->getCode()).".png")?>"
                                             width="16" height="11"
                                             alt="<?=$language->getName()?>"
                                             title="<?=$this->message("title.translate.item", _Core::BUNDLE)?> (<?=$language->getName()?>)."
                                             class="flag" />
                                     </a>
                                <? } ?>
                            <? } ?>

                        </td>
                    <? endif; ?>

                <? endif; ?>

                <td class="buttons">

                    <input type="button"
                           onclick="to('content/edit?contentI18n->contentI18nId=<?=$contentI18n->getContentI18nId()?>')"
                           class="button"
                           value="<?=$this->message("button.edit", _Core::BUNDLE)?>" />

                    <input type="button"
                           onclick="del(<?=$contentI18n->getContentI18nId()?>, '<?=get_class($this->contentListForm)?>')"
                           class="button"
                           value="<?=$this->message("button.delete", _Core::BUNDLE)?>" />

                </td>
            </tr>

            <? /* Loop through the foreign languages when i18n enabled & language selectbox is on ALL */?>
            <? if($this->param(_Core::I18N) && strlen($this->contentListForm->getLanguage()) == 0 && strlen($this->contentListForm->getQuery()) == 0): ?>

                <?
                $i18nContents = $contentI18n->getForeignContent18ns($this->param(_Core::DEFAULT_LANGUAGE));
                for($i=0; $i<count($i18nContents); $i++) { ?>
                <tr class="ctrlsub">
                    <td class="checkbox">

                        <input type="checkbox"
                           name="items[]"
                           value="<?=$i18nContents[$i]->getContentI18nId()?>"
                           <?=in_array($i18nContents[$i]->getContentI18nId(), $this->contentListForm->getItems()) ? " checked=\"checked\"" : ""?> />

                    </td>
                    <td></td>
                    <td title="<?=$this->message("title.language", _Core::BUNDLE)?>">

                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($i18nContents[$i]->getLanguage()->getCode()).".png")?>"
                             width="16" height="11"
                             alt="<?=$i18nContents[$i]->getLanguage()->getName()?>"
                             title="<?=$this->message("title.translation", _Core::BUNDLE)?> (<?=$i18nContents[$i]->getLanguage()->getName()?>)" />

                    </td>
                    <td class="translation" title="<?=htmlentities($i18nContents[$i]->getName())?>">

                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/arrow_merge.png")?>"
                             title="<?=$this->message("title.translation", _Core::BUNDLE)?> (<?=$i18nContents[$i]->getLanguage()->getName()?>)"
                             width="16" height="16" alt="" class="arrow" />
                        <?=$this->truncateNicely($i18nContents[$i]->getName(), 13, 18, "...")?>

                    </td>
                    <td></td>
                    <td title="<?=$this->message("title.modified", _Core::BUNDLE)?> <?=$i18nContents[$i]->getModifiedDate(_Core::FORMAT_DATETIME)?>">
                        <?=$i18nContents[$i]->getModifiedDate(_Core::FORMAT_DATE)?>
                    </td>
                    <td title="<?=$this->message("title.created", _Core::BUNDLE)?> <?=$i18nContents[$i]->getInsertDate(_Core::FORMAT_DATETIME)?>">
                        <?=$i18nContents[$i]->getInsertDate(_Core::FORMAT_DATE)?>
                    </td>
                    <td title="<?=$this->message("title.featured", _Core::BUNDLE)?>">
                        <?=$this->message("label." . ($i18nContents[$i]->getFeatured() ? "yes" : "no"), _Core::BUNDLE)?>
                    </td>
                    <td title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                        <?=$this->message("label." . ($i18nContents[$i]->getActive() ? "yes" : "no"), _Core::BUNDLE)?>
                    </td>
                    <td></td>
                    <td></td>
                    <td class="buttons">

                        <input type="button"
                               onclick="to('content/edit?contentI18n->contentI18nId=<?=$i18nContents[$i]->getContentI18nId()?>')"
                               class="button"
                               value="<?=$this->message("button.edit", _Core::BUNDLE)?>" />

                        <input type="button"
                               onclick="del(<?=$i18nContents[$i]->getContentI18nId()?>, this.form)"
                               class="button"
                               value="<?=$this->message("button.delete", _Core::BUNDLE)?>" />

                    </td>
                </tr>
                <? } ?>
                
            <? endif; ?>

        <? } ?>

        </table>


        <? /* Edit/Action Bar for checkboxed */ ?>
        <?=$this->edit(
            $this->contentListForm, // ListForm
            array(               // The actions
                "activate"=>$this->message("choose.activate", _Core::BUNDLE),
                "deactivate"=>$this->message("choose.deactivate", _Core::BUNDLE),
//                "feature"=>$this->message("choose.feature", _Core::BUNDLE),
                "delete"=>$this->message("choose.delete", _Core::BUNDLE)
            )
        )?>


        <? /* End output buffering */ ?>
        <?$this->end(
            $this->contentListForm,                                                           // ListForm
            "content/edit?contentI18n->content->categoryId=".$this->contentListForm->getId(), // Add New URL
            $this->contents($this->contentListForm)->getRows()                                // The total amount of contents
        )?>


    </form>

<?=$this->footer()?>